package com.zt.chatglm.executor;

import com.zt.chatglm.domain.chat.ChatCompletionRequest;
import com.zt.chatglm.domain.chat.ChatCompletionSyncResponse;
import com.zt.chatglm.domain.image.ImageCompletionRequest;
import com.zt.chatglm.domain.image.ImageCompletionResponse;
import okhttp3.sse.EventSource;
import okhttp3.sse.EventSourceListener;

import java.io.IOException;
import java.util.concurrent.CompletableFuture;

/**
 * @author: zt
 * @Description: 请求调用抽象接口
 * @create: 2024-05-20 22:42
 */

public interface Executor {


    /**
     * 问答模式，流式反馈
     *
     * @param completionRequest 请求信息
     * @param eventSourceListener   实现监听；通过监听的 onEvent 方法接收数据
     * @return 应答结果
     * @throws Exception 异常
     */
    EventSource completions(ChatCompletionRequest completionRequest, EventSourceListener eventSourceListener) throws Exception;


    /**
     * 问答模式，同步反馈 —— 用流式转化 Future
     *
     * @param completionRequest 请求信息
     * @return 应答结果
     */
    CompletableFuture<String> completions(ChatCompletionRequest completionRequest) throws Exception;

    /**
     * 同步应答接口
     *
     * @param completionRequest 请求信息
     * @return ChatCompletionSyncResponse
     * @throws IOException 异常
     */
    ChatCompletionSyncResponse completionsSync(ChatCompletionRequest completionRequest) throws Exception;


    /**
     * 图片生成接口
     *
     * @param request 请求信息
     * @return 应答结果
     */
    ImageCompletionResponse genImages(ImageCompletionRequest request) throws Exception;
}
